
$(function() {

	$("input[id^='material_s']:visible").autocomplete(Test.material);
	
	_change("input[id='place']:visible", "select[id^='place_t']:visible");
	
	$("select[id^='category_']:visible").selectChain({
		target: $("select[id^='subclass_']:visible"),
		key: "code",
		value: "name",
		url: 'material.php?do=PanDian.ajax_category',
		data: { ajax: true }
	}).trigger('change');
	
	Tip.emp('负责人');
});

var PanDian = {	
	popup: function (e, p2, id, status) {
		$.cookie('id_', id);

		$.cookie('status_', status);

		p2 = query(p2);
		$.cookie('p2', p2);

		var c1 = 'material.php?do=PanDian.edit&id=' + id;
		var c2 = 'material.php?do=PanDian.view&id=' + id;

		var a1 = ['编辑信息', 'url', 'PanDian.dialog_edit_', '650x440'];
		var a2 = ['查看信息', 'url', 'Common.dialog_view_', '650x400'];

		var s = c1 + ", " + c2;

		return popup(e, [a1, a2], s);
	},

	dialog_edit_: function (url, title, xy) {
		var result = Common.result();
		$.getJSON('material.php?do=PanDian.ajax_emp', function(json) {
			if (json.status == 1) {
				$('#dialog_edit').dialog('option', 'buttons', {
					"关闭": function() {
						$(this).dialog("close");
					},

					"修改": function() {
						if (!confirm("确认是否提交？")) {
							return false;
						}

						var form = $("#form_edit")[0];

						var body = {};
						body.id = form.id.value;
						
						body.emp = form.emp.value;
						body.date = form.date.value;
						
						body.place = form.place.value;
						
						body.name = form.name.value;						
						body.standard = form.standard.value;						
						body.unit = form.unit.value;
						body.price = form.price.value;
												
						body.kc = form.kc.value;
						body.pd = form.pd.value;
						body.amount = form.amount.value;
						
						body.total = form.total.value;
						
						body.content = form.content.value;
						body.status = form.status.value;

						$(this).dialog("close");

						var url = 'material.php?do=PanDian.editPost';
						var p2 = $.cookie('p2');
						if (p2 != null) {
							url += p2;
						}

						$.post(url, body, function(data) {
							$(result).html(data);
						});
					}
				});

				dialog_edit(url, title, xy);
			} else {
				_error();
			}
		});
	},
	
	popup_all: function (e, p2) {
		p2 = query(p2);
		$.cookie('p2', p2);

		var c1 = 'material.php?do=PanDian.delete' + p2;
		var c9 = 'material.php?do=PanDian.xls' + p2;	
			
		var a1 = ['删除信息', 'url', 'Common.list_delete'];				
		var a9 = ['导出Excel', 'url', 'jswin', '1024x768'];

		var s = c1 + ", " + c9;

		return popup(e, [a1, a9], s);
	}
};
